//
//  AddBankCardViewController.m
//  跨界收
//
//  Created by Allen on 2018/10/28.
//  Copyright © 2018年 gztx. All rights reserved.
//

#import "AddBankCardViewController.h"
#import "AddBankCardTableViewCell.h"
#import "AddBankCardFooterView.h"
#import "PutForwardViewController.h"
#import "LYLPhotoTailoringTool.h"

@interface AddBankCardViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *cardTableview;
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) AddBankCardFooterView *footerView;
@property (nonatomic, strong) NSMutableArray *contents;
@end

@implementation AddBankCardViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"添加银行卡";

    _contents = [NSMutableArray arrayWithCapacity:_titles.count];
    for (int i = 0; i < _titles.count; i++) {
        [_contents addObject:@""];
    }
  
    self.cardTableview.delegate = self;
    self.cardTableview.dataSource = self;
    [self.cardTableview registerNib:[UINib nibWithNibName:@"AddBankCardTableViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
    _titles = @[@"持卡人姓名",@"银行卡号",@"开户行",@"手机号码",@"验证码"];
    self.footerView = [AddBankCardFooterView shareIntance];
    WeakSelf;
    self.footerView.sendblock = ^(UIButton * _Nonnull sender) {
        switch (sender.tag) {
            case 100:{
                [[LYLPhotoTailoringTool sharedTool]photoTailoring:^(UIImage *image) {
                    [sender setImage:image forState:UIControlStateNormal];
                }];
            }
                break;
            case 101:{
                [[LYLPhotoTailoringTool sharedTool]photoTailoring:^(UIImage *image) {
                     [sender setImage:image forState:UIControlStateNormal];
                }];
            }
                break;
            case 103:{
                PutForwardViewController *pfVC = [[PutForwardViewController alloc] initWithNibName:@"PutForwardViewController" bundle:nil];
                [weakSelf.navigationController pushViewController:pfVC animated:YES];
            }
                break;
            default:
                break;
        }
    };
//    self.cardTableview.tableFooterView = self.footerView;
 
}

#pragma mark -- UITableViewDelegate/DataSource --
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return self.footerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 256;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titles.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    AddBankCardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[AddBankCardTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.titleLabel.text = _titles[indexPath.row];
    cell.contentTextField.placeholder = [NSString stringWithFormat:@"填写%@",_titles[indexPath.row]];
    if (indexPath.row == _titles.count-1) {
        cell.getCodeBtn.hidden = NO;
        cell.rightConstraint.constant = 85;
        [cell.getCodeBtn addClickTargetBlock:^(UIButton *sender) {
            [sender countdownTimerWithInterval:60 progressBlock:^(UIButton *sender, NSInteger time) {
                [sender setTitle:[NSString stringWithFormat:@"%ld秒",time] forState:UIControlStateNormal];
            } successBlock:^(UIButton *sender) {
                [sender setTitle:@"获取验证码" forState:UIControlStateNormal];
            }];
        }];
    }
    return cell;
}

@end
